<?php

class DDZ
{
    public function __construct(){
        $this->create();
        $this->distribute();
    }

    /*
     * 创建扑克牌
     */
    public function create(){
        $king = ['大王', '小王'];
        $color = ['红桃', '方块', '黑桃', '梅花'];
        $value = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
        $group = [];
        foreach ($color as $c) {
            foreach ($value as $v) {
                $group[] = $c.$v;
            }
        }
        $this->cards = array_merge($group, $king);
    }

    /*
     * 发牌
     * $p玩家人数，$q地主牌数
     */
    public function distribute($p = 3, $q = 3){
        $player = [];
        $left = 54 - $q;
        for ($i = 0; $i < $p; $i++) {
            $result = array_rand($this->cards, $left/$p);
            foreach ($result as $r) {
                $player[$i][] = $this->cards[$r];
                unset($this->cards[$r]);
            }
        }
        $this->player = $player;
        $this->landlord = $this->cards;
    }
}
